18. Arrays
Arrays
In the previous exercise, we included an array of directional deltas for convenience:
// directional deltas
const int delta[4][2]{{-1, 0}, {0, -1}, {1, 0}, {0, 1}};
Arrays are a lower level data structure than vectors, and can be slightly more efficient, in terms of memory and element access. However, this efficiency comes with a price. Unlike vectors, which can be extended with more elements, arrays have a fixed length. Additionally, arrays may require careful memory management, depending how they are used.
The example in the project code is a good use case for an array, as it was not intended to be changed during the execution of the program. However, a vector would have worked there as well.
Let's hear what Bjarne has to say about arrays in C++:
ND213 C01 Prefer Vectors Over Arrays What Is An Array-